<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>转手商城-个人资料</title>
		<link rel="stylesheet" type="text/css" href="../../static/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/css/admin.css" />

		<script src="../../static/js/public/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/jquery.session.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/util.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="layui-tab page-content-wrap" id="info">
			<ul class="layui-tab-title">
				<li class="layui-this">修改资料</li>
				<li>修改密码</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<form class="layui-form" style="width: 90%;padding-top: 20px;" @submit.prevent="onSubmit">
						<div class="layui-form-item">
							<label class="layui-form-label">ID：</label>
							<div class="layui-input-block">
								<input type="text" name="aid" disabled autocomplete="off" class="layui-input layui-disabled" v-model="aid">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">账号：</label>
							<div class="layui-input-block">
								<input type="text" name="account" disabled autocomplete="off" class="layui-input layui-disabled" v-model="account">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">昵称：</label>
							<div class="layui-input-block">
								<input type="text" name="name" placeholder="请输入昵称" autocomplete="off" class="layui-input" v-model="name">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">权值：</label>
							<div class="layui-input-block">
								<input type="text" name="root" placeholder="请输入权值(权值越小权限越大)" autocomplete="off" class="layui-input" v-model="root">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="adminInfo" @click="setInfo()">立即提交</button>
							</div>
						</div>
					</form>
				</div>
				<div class="layui-tab-item">
					<form class="layui-form" v style="width: 90%;padding-top: 20px;" @submit.prevent="onSubmit">
						<div class="layui-form-item">
							<label class="layui-form-label">ID：</label>
							<div class="layui-input-block">
								<input type="text" name="aid" disabled autocomplete="off" class="layui-input layui-disabled" v-model="aid">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">账号：</label>
							<div class="layui-input-block">
								<input type="text" name="account" disabled autocomplete="off" class="layui-input layui-disabled" v-model="account">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">新密码：</label>
							<div class="layui-input-block">
								<input type="password" name="password" placeholder="请输入密码" autocomplete="off" v-model="password" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">重复密码：</label>
							<div class="layui-input-block">
								<input type="password" name="password_" placeholder="请输入密码" autocomplete="off" v-model="password_" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="adminPassword" @click="setPwd()">立即提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>

		<script type="text/javascript">
			var vm = new Vue({
				el: '#info',
				data: {
					aid:'',
					account:'',
					name: '',
					password:'',
					password_:'',
					root:0
				},
				methods: {
					loadInfo() { //查看管理员信息
						var _this = this;
						axios({
							method: 'get',
							url: getRootURL() + 'admin/get-admin',
							data: {},
							headers: {
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);
		
							if (res.data.status >= 0) {
								_this.aid = res.data.object.aid
								_this.account = res.data.object.account
								_this.name = res.data.object.name
								_this.root = res.data.object.root
							} else {
								alert(res.data.msg);
							}
		
						}).catch(function(err) {
							alert(err);
						});
					},
					setInfo() { //修改管理员信息
						if (validityForStringNull(this.$data.name, "昵称不能为空") ||
							validityForStringNull(this.$data.root, "权限不能为空")) {
							return;
						}
						
						if(!isRealNum(this.$data.root, "权限只能为数字")){
							return;
						}
					
						var _this = this;
						axios({
							method: 'post',
							url: getRootURL() + 'admin/set-admin',
							data: {
								"name":_this.$data.name,
								"root":_this.$data.root
							},
							headers: {
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);
							
							if (res.data.status >= 0) {
								alert(res.data.msg);
							} else {
								alert(res.data.msg);
							}
							
						}).catch(function(err) {
							alert(err);
						});
					},
					setPwd() { //修改密码
						if (validityForStringNull(this.$data.password, "新密码不能为空") ||
							validityForStringNull(this.$data.password_, "重复密码不能为空")) {
							return;
						}
						
						if(this.$data.password!==this.$data.password_){
							alert("两次密码不一致");
							return;
						}
					
						var _this = this;
						axios({
							method: 'post',
							url: getRootURL() + 'admin/set-admin',
							data: {
								"password":_this.$data.password,
							},
							headers: {
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);
							
							if (res.data.status >= 0) {
								alert(res.data.msg);
							} else {
								alert(res.data.msg);
							}
							
						}).catch(function(err) {
							alert(err);
						});
					},
					onSubmit() {
						//防止form冒泡
						return false;
					}
				},
				created() {
					this.loadInfo()
				},
				mounted() {
		
				}
			})
		</script>

		<script>
			layui.use(['form', 'element'], function() {
				var form = layui.form();
				var element = layui.element();
			});
		</script>

	</body>
</html>
